package com.test.synchronizationTool;

import java.util.concurrent.CountDownLatch;

/**
 * 值日生要等所有人走后，才能打扫卫生关灯锁门
 *
 * @author wangjie
 * @version V1.0
 * @date 2019/12/19
 */
public class CountDownLatchDemo1 {

    public static void main(String[] args) throws Exception {
        closeDoor();

    }

    /**
     * 值日生案例
     * @throws InterruptedException
     */
    private static void closeDoor() throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t" + "放学离开");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t值日生打扫卫生锁门");
    }
}
